<template>
  <table-row-detail-dialog
    :dialogTitle="title"
    @confirm="handleConfirm"
    ref="inspectionDialog"
    class="inspectionDialog"
    dialogWidth="80%"
  >
    <template v-if="dialogType == 'detail'">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="早巡检" name="0">
          <inspection ref="inspection1"></inspection>
        </el-tab-pane>
        <el-tab-pane label="晚巡检" name="1">
          <inspection ref="inspection2"></inspection>
        </el-tab-pane>
      </el-tabs>
    </template>
    <template v-else>
      <inspection ref="inspection"></inspection>
    </template>
    
  </table-row-detail-dialog>
</template>

<script>
import TableRowDetailDialog from '@/components/TableRowDetailDialogNew/index';
import inspection from './components/inspection';
export default {
  name: 'DialogInspection',
  props: {
    title: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      activeName: 0,
      dialogType: ''
    };
  },
  components: {
    TableRowDetailDialog,
    inspection
  },
  mounted() {
    // this.handelData(this.data)
  },
  methods: {
    handleClick(tab, event) {
      // console.log(tab, event);
      this.$emit('tabClick', this.activeName)
    },
    handleConfirm() {
      var ids = []
      this.$refs.inspection.checked1.forEach(item => ids.push(item.id));
      this.$refs.inspection.checked2.forEach(item => ids.push(item.id));
      this.$refs.inspection.checked3.forEach(item => ids.push(item.id));
      this.$emit('submit', ids);
    },
    show(val, rows, require, tabClick) {
      if(tabClick=='show'){
        this.activeName = '0'
      }
    
      if(require == 1){
        this.dialogType = val
      }else{
        this.dialogType = ''
      }
      this.$refs.inspectionDialog.show(val);
      if(this.dialogType == 'detail') {
        this.$nextTick(() => {
          console.log(this.$refs)
          this.$refs.inspection1.data = rows
          this.$refs.inspection1.show(val);
          this.$refs.inspection2.data = rows
          this.$refs.inspection2.show(val);
        })
      } else {
        this.$nextTick(() => {
          this.$refs.inspection.data = rows
          this.$refs.inspection.show(val);
        })
      }
    },
    hide() {
      this.$refs.inspectionDialog.hide();
      this.$refs.inspection.data = []
    }
  }
};
</script>
<style>
.inspectionDialog .wrapper .dialog .body {
  height: 75vh;
}
.el-theme1 .inspectionDialog .el-tabs__nav{
  left: calc(50% - 62px);
}
</style>
